#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#define ERR_EXIT(m) \
do \
{ \
perror(m); \
exit(EXIT_FAILURE); \
} while(0)

int main(int argc,char* argv[]){
    int fds[2];
    int len;
    if(pipe(fds)==-1) ERR_EXIT("pipe erro");

    int pid = fork();
    if(pid == -1) ERR_EXIT("fork errro");
    if(pid == 0){
        close(fds[0]);
        //char arr[] = "hello world!";
        write(fds[1],"hello", 5);
        close(fds[1]);
        exit(EXIT_SUCCESS);
    }
    close(fds[1]);
    char arr[20] = {0};
    read(fds[0],arr,20);
    //close(fds[0]);
    printf("%s\n",arr);
    return 0;
}